<template>
  <router-view />
</template>

<style lang="scss"></style>
<script setup>
import { onBeforeMount } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";
const router = useRouter(); // 获取路由跳转
let store = useStore();

// 获取登录状态
onBeforeMount(() => {
  // 判断登录信息是否超过有效期
  if (document.cookie) {
    // ElMessage({
    //   message: "欢迎回来",
    //   type: "success",
    // });
    // router.push({ path: "/home" });
    let info = document.cookie.replace(/\s*/g, "").split(";");
    let obj = {};
    info.map((item) => {
      item.split("=");
      let keyName = item.split("=")[0];
      let keyVal = item.split("=")[1];
      obj[keyName] = keyVal;
    });
    store.commit("getUserInfo", obj);
  } else {
    router.push({ path: "/" });
    ElMessage({
      message: "请先进行登录",
      type: "success",
    });
  }
});
</script>
